//
//  VECanDrewwithViewController.m
//  VEMoneyPorject
//
//  Created by BlueWind on 2018/9/30.
//  Copyright © 2018 陈建. All rights reserved.
//

#import "VECanDrewwithViewController.h"

#import "VECanDrewwithTableViewCell.h"

@interface VECanDrewwithViewController ()

@end

@implementation VECanDrewwithViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.refreshType = CJBaseTableVcRefreshTypeRefreshAndLoadMore;
    [self cj_refresh];
}


- (void)cj_refresh{
    [super cj_refresh];
    [self loadData];
}

- (void)loadData{
    [super loadData];
    [self requestDataWithType:1];
    
}

- (void)cj_loadMore{
    [super cj_loadMore];
    NSLog(@"%ld",self.page);
    [self requestDataWithType:2];
    
}

- (void)requestDataWithType:(NSInteger)type{
    
    NSString *url = [NSString stringWithFormat:@"%@/VEService/GetKetixian.do",kPublicInterfaceAPI];
    
    NSDictionary *dic = @{
                          @"Userid": [CJUserInfoManager sharedManager].currentUserInfo.USERID,
                          @"Time": [NSDate currentDateStringWithFormat:@"yyyy-MM-dd"],
//                          @"Time":@"2018-10-20",
                          @"Page": @(self.page)
                          };
    
    CJBaseRequest *request = [CJBaseRequest cj_requestWithUrl:url isPost:YES withParameters:dic];
    [request cj_sendRequestWithCompletion:^(id response, BOOL success, NSString *message) {
        [self cj_endRefresh];
        [self cj_endLoadMore];
        self.isSuccessNet = YES;
        
        
        if (![NSObject isNilOrNull:response]) {
            NSArray *arr = response;
            if (arr.count == 0) {
                self.page -=1;
                return;
            }
            if (type == 1) {
                [self.dataArray removeAllObjects];
                self.dataArray = [VEWaitDrewwithModel mj_objectArrayWithKeyValuesArray:arr];
            } else {
                NSArray *arr1 = [VEWaitDrewwithModel mj_objectArrayWithKeyValuesArray:arr];
                [self.dataArray addObjectsFromArray:arr1];
            }
            
            
            
            [self.tableView reloadData];
        }
    }];
}


- (NSInteger)cj_numberOfSections {
    return 1;
}

/**
 某个cell的数量
 */
- (NSInteger)cj_numberOfRowsInsection:(NSInteger)section {
        return self.dataArray.count;
//    return 1;
}

- (CGFloat)cj_cellHeightAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

/**
 某行的cell
 */
- (CJBaseTableViewCell *)cj_cellAtIndexPath:(NSIndexPath *)indexPath {
    
    VECanDrewwithTableViewCell *cell = [VECanDrewwithTableViewCell cellWithTableView:self.tableView];
    
    VEWaitDrewwithModel *model = self.dataArray[indexPath.row];
    cell.model = model;
    
    
#pragma mark *******************提现操作****************
    cell.clickTixian = ^{
        NSString *url = [NSString stringWithFormat:@"%@/VEService/Tixianbishu.do",kPublicInterfaceAPI];
        
        NSDictionary *dic = @{
                              @"saveid": model.SAVEID,
                              };
        
        CJBaseRequest *request = [CJBaseRequest cj_requestWithUrl:url isPost:YES withParameters:dic];
        [request cj_sendRequestWithCompletion:^(id response, BOOL success, NSString *message) {
            [self cj_endRefresh];
            [self cj_endLoadMore];
            self.isSuccessNet = YES;
            
            
            if (![NSObject isNilOrNull:response]) {
             
            }
        }];
    };
    
    return cell;
    
    
}


@end
